package cn.lanqiao.bigDate.service.data.impl;

import cn.lanqiao.bigDate.entity.data.DataBookOrder;
import cn.lanqiao.bigDate.entity.sys.SysArea;
import cn.lanqiao.bigDate.mapper.data.DataBookOrderMapper;
import cn.lanqiao.bigDate.mapper.sys.SysAreaMapper;
import cn.lanqiao.bigDate.service.data.DataStockService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DataStockServiceImpl implements DataStockService {
    @Resource
    private DataBookOrderMapper dataBookOrderMapper;
    @Resource
    private SysAreaMapper sysAreaMapper;

    /**
     * 月的销售地区与销量
     * @return
     */
    @Override
    public Map<String, Object> findThirdMapData(){
        QueryWrapper<DataBookOrder> wrapperDataBookOrder = new QueryWrapper<>();
        wrapperDataBookOrder.select("quantity","place_shipment");
        List<DataBookOrder> dataBookOrders = dataBookOrderMapper.selectList(wrapperDataBookOrder);
        String[] place = new String[dataBookOrders.size()];
        for (int i = 0; i < dataBookOrders.size(); i++) {
            place[i]=dataBookOrders.get(i).getPlaceShipment();
        }
        QueryWrapper<SysArea> wrapperSysArea = new QueryWrapper<>();
        wrapperSysArea.in("area_code",place);
        List<SysArea> sysAreas  = sysAreaMapper.selectList(wrapperSysArea);
        Map<String, Object> map = new HashMap<>();
        map.put("sysAreas",sysAreas);
        map.put("dataBookOrders",dataBookOrders);
        return map;
    }
}
